home *** CD-ROM | disk | FTP | other *** search
- Path: news.sprintlink.net!datalytics!usenet
- From: Rob Stewart <stew@datalytics.com>
- Newsgroups: comp.lang.c++
- Subject: Re: Arrays or Pointers?
- Date: Mon, 08 Apr 1996 16:57:28 -0400
- Organization: Datalytics, Inc
- Message-ID: <31697DB8.41A7@datalytics.com>
- References: <4kbsk3$f07@zeus.tcp.co.uk>
- NNTP-Posting-Host: 204.62.224.71
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (WinNT; I)
-
- David wrote:
- >
- > I'm currently on a C++ course and we seem to be using pointers a fair
- > bit. On questioning this, was told that pointers where quicker than
- > using arrays. In which situations should I be using arrays over
- > pointers and vice versa?
- >
-
- I had read, many years ago, that on several systems, some tests
- revealed that pointer arithmetic to access an array was faster
- than the equivalent array notation. As a result of that, and
- since I wasn't terribly comfortable with pointers at that time,
- I committed to using pointers for array accesses as well as more
- "normal" purposes. The benefit was that I became thoroughly
- familiar with pointers.
-
- We recently did some tests with our current compilers: Microsoft
- Visual C++ 2.2 and 4.0, and found that they produced identical
- code. In fact, the code was no different with or without
- optimizations turned on. In other words, assuming there was a
- difference years ago, there is likely no difference in today's
- compilers. You'll need to conduct tests for yourself with your
- compiler to see if it does as well.
-
- Since junior programmers are less familiar with pointers than
- arrays, I have reverted to using array syntax again.
-
- --
- Robert Stewart | My opinions are usually my own.
- Datalytics, Inc. | stew@datalytics.com
-